package com.Maykk.Demo04;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @ClassName: Demo03
 * @Description: TODO List 集合的遍历
 * @Author: MaykkStar@163.com
 */
public class Demo03 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
        // 方法一
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("=====================");

        // 方法二
        for (String string : list) {
            System.out.println(string);
        }

        System.out.println("=====================");

        // 方法三
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        System.out.println("=====================");

        // 方法四
        list.stream().forEach(System.out::println);

        System.out.println("=====================");

        // 方法五
        list.forEach(System.out::println);
    }
}
